#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;


#define MAX_N 100000
char characters[MAX_N + 5];

int main()
{
    cin >> characters;
    int n = strlen(characters);
    int varieties = 0;
    int hash[26];
    memset(hash, 0, sizeof hash);
    long long ret = 0;
    for(int left = 0, right = 0; right < n; right++)
    {
        if(hash[characters[right] - 'a']++ == 0)
        {
            varieties += 1;
        }
        while(varieties > 2)
        {
            if(--hash[characters[left++] - 'a'] == 0)
                varieties -= 1;
        }
        ret = max(ret, (long long)(right - left + 1));
    }
    cout << ret;
    return 0;
}